/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.diamondsys.embrapa;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Rafael
 */
@Stateless
public class TbInstFacade extends AbstractFacade<TbInst> {
    @PersistenceContext(unitName = "com.diamondsys_embrapa_war_1.0-SNAPSHOTPU")
    private EntityManager em;

    /**
     *
     * @return
     */
    @Override
    public EntityManager getEntityManager() {
        return em;
    }

    /**
     *
     */
    public TbInstFacade() {
        super(TbInst.class);
    }
    
    public List<TbInst> findByeventId(int eventId) {
        return em.createNativeQuery(   "  SELECT t.* FROM `nco`.`tb_inst` t, `nco`.`participante_evento` p"
                                     + "   WHERE t.`cod_instituicao` = p.`tb_inst_cod_instituicao`"
                                     + "     AND p.`sigif_eventosint_ideventosint` = :eventId", TbInst.class)
                .setParameter("eventId", eventId)
                .getResultList();
    } 
    
    public int deletaParticipantesEvento(int eventId) {
        return em.createNativeQuery(   "  DELETE FROM `nco`.`participante_evento`"
                                     + "   WHERE `sigif_eventosint_ideventosint` = :eventId")
                .setParameter("eventId", eventId)
                .executeUpdate();
    }     
    
    @Override
    public List<TbInst> findAll() {
        return em.createNamedQuery("TbInst.findAll", TbInst.class).getResultList();
    }          
}
